import request from "@/utils/request";
const BASE_URL = "/order";

const OrderAPI = {
  getList(queryParams?: OrderQuery) {
    return request<any, PageResult<OrderPageVO[]>>({
      url: `${BASE_URL}/list`,
      method: "get",
      params: queryParams,
      data: queryParams,
    });
  },
  getFormData(id: number) {
    return request<any, OrderVO>({
      url: `${BASE_URL}/${id}`,
      method: "get",
    });
  },

  getPayResult(id: string) {
    return request<any, any>({
      url: `/payNotify/thankyou/${id}`,
      method: "get",
    });
  },

  add(data: OrderVO) {
    return request({
      url: `${BASE_URL}/create`,
      method: "post",
      data: data,
    });
  },

  update(data: OrderVO) {
    return request({
      url: `${BASE_URL}/update`,
      method: "POST",
      data: data,
    });
  },

  deleteByIds(id: number) {
    return request({
      url: `${BASE_URL}/delete/${id}`,
      method: "get",
    });
  },

  getOrderPaymentInfo(id: number) {
    return request<any, any>({
      url: `${BASE_URL}/getOrderPaymentInfo/${id}`,
      method: "get",
    });
  },
};

export default OrderAPI;

export interface OrderPageVO {
  id: number;
  title: string;
  payMethod: string;
  status: number;
  openStatus: number;
  createdAt: string;
  customerId: number;
  productId: number;
}

export interface OrderVO {
  id: number;
  payMethod: string;
  status: number;
  productId: number | undefined;
  customerId: number;
  paymentResponse?: string;
}

export interface PageVO {
  id: number;
  title: string;
  price: number;
  days: number;
}

export interface Query extends PageQuery {
  keywords?: string;
}

export interface OrderQuery extends PageQuery {
  pageNum: 1;
  pageSize: 10;
  keywords: "";
  status: 9;
}

export interface Form {
  id: number;
  title: string;
  price: number;
  days: number;
  sort: number;
}
